#ifndef CONTACT_H
#define CONTACT_H

# include	<QtCore/QObject>
# include	<QtWidgets/QWidget>
# include	<QtWidgets/QMenu>
# include	<QtWidgets/QPushButton>
# include	<QtWidgets/QMessageBox>
# include	<QtWidgets/QDialog>
# include	<QtWidgets/QVBoxLayout>
# include	<QtWidgets/QHBoxLayout>
# include	<QtWidgets/QSlider>
# include	<QtWidgets/QListWidget>
# include	<QtWidgets/QLabel>
# include	<QtWidgets/QLineEdit>
# include	<QtWidgets/QCheckBox>
# include	<QtCore/QString>
# include	<QtCore/QStringListModel>
# include	<iostream>
# include	"contact_global.h"
# include	"IOrder.h"
# include	"IModule.h"
# include	"BabelApi.h"
# include	"ClientManager.h"
# include	"Client.h"
# include	"Protocol.h"

class								User;

#if defined __linux__
class __attribute__((visibility ("default"))) Contact : public QObject, public IModule
#else
class __declspec(dllexport)                     Contact : public QObject, public IModule
#endif
{
	Q_OBJECT
	enum Operator : byte
	{
		LOGIN = 0,
		LIST = 1,
		OCALL = 2,
		WHO = 3,
		OK = 4,
		KO = 5,
		WELCOME = 6,
		PING = 7,
		PONG = 8,
		REMOVE = 10
	};
public:
	Contact();
	virtual ~Contact();
	virtual void					takeOrder(IOrder *, Protocol);
	virtual void					test();
	virtual std::vector<Protocol>	getProtocol() const;
	virtual void					setApi(BabelApi *);
	virtual void					init();

public slots:
	void							onAddActionTriggered();
	void							ConfirmLogin();

private:
	BabelApi						*_api;
	std::vector<Protocol>			_proto;
	QMenu							*_menu;
	QDialog							*_loginWindow;
	QLineEdit						*_login;
	QLineEdit						*_password;
	QPushButton						*_buttonconfirm;
	QAction							*_addContact;
	QListWidget						*_listContact;
	IClientManager					*_client;
	std::map<Operator, void (Contact::*)(IOrder *)>	_operator;

private:
	void							addMenuContact();
	void							addListContact();
	void							OpenLoginWindow();
	void							list(IOrder *);
	void							who(IOrder *);
	void							refreshList();
	void							welcome(IOrder *);
	void							ping(IOrder *);

public slots:
	void							userClicked(QListWidgetItem *);
signals:
	void							_selectedClient(unsigned int);
};

class								User : public QString
{
public:
	User(const char * user) : QString(user) {}

public:
	int								getIdUser() const;
	void							setIdUser(int);

private:
	int								_id;
};

#endif // CONTACT_H
